
#include <iostream>
#include <string>
#include "serve.h"
#include "Log.h"
#include "Intaddr.h"

struct sockaddr_in;

// 调用方式: ./serve port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "使用方式错误,正确调用方式 ./serve port" << std::endl;
        exit(-1);
    }
    zmh::Intaddr serve_addr(AF_INET, std::stoi(argv[1]));

    auto handler = [](const std::string &mesage, const zmh::Intaddr &peer, int id)
    {
        if (sendto(id, mesage.c_str(), mesage.size(), 0, (struct sockaddr *)&peer, sizeof(peer)) == -1)
        {
            LOG(zmh::LogLevel::ERROR) << "send mistake:" << strerror(errno);
            exit(errno);
        }
    };

    zmh::serve ser(serve_addr, handler);
    ser.start();
    return 0;
}
